package com.bluesky.plum.uimodels.render.html.components;

import com.bluesky.javawebbrowser.domain.html.HtmlPage;
import com.bluesky.javawebbrowser.domain.html.tags.form.input.Text;
import com.bluesky.plum.richdomain.RichDomainField;

public class HTextBox extends
		com.bluesky.plum.uimodels.standard.components.TextBox {

	private Text textbox;

	public HTextBox(RichDomainField field) {
		super(field);

	}

	@Override
	public void initialize() {
		super.initialize();

		if (template != null && template.length() > 0) {
			HtmlPage page = new HtmlPage(template);
			textbox = (Text) page.getRoot().getById(
					componentType.toString());
		} else {
			textbox = new Text();
		}

		textbox.setValue((String) getField().value);

	}

	@Override
	public Object getNativeComponent() {
		textbox.setId(getId());
		textbox.setName(getId());

		return textbox;
	}

	@Override
	public String getText() {

		return textbox.getValue();
	}

	@Override
	public void setText(String text) {

		textbox.setValue(text);
		System.out.println("set textbox: " + text);
	}
}
